/*
 * Created on Oct 9, 2009
 * (c) 2009 by Reach Unlimited Corporation
 */
package com.mgmaps.maps;

import com.nutiteq.components.MapTile;
import com.nutiteq.maps.MapTileOverlay;

public class MicrosoftTrafficOverlay implements MapTileOverlay {
  public static final MicrosoftTrafficOverlay TRAFFIC = new MicrosoftTrafficOverlay();
  
  public String getOverlayTileUrl(final MapTile tile) {
    final int tmpX = tile.getX() >> 8;
    final int tmpY = tile.getY() >> 8;
    final int zoom = tile.getZoom();

    final StringBuffer buf = new StringBuffer("http://t");
    buf.append(((tmpY & 1) << 1) + (tmpX & 1));
    buf.append(".tiles.virtualearth.net/tiles/dp/content?p=tf&a=");
    for (int i = zoom - 1; i >= 0; i--)
      buf.append((((tmpY >> i) & 1) << 1) + ((tmpX >> i) & 1));

    return buf.toString();
  }
}